//
//  MjModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit

enum MJType: Int {
    case km2 = 0
    case ha
    case are
    case m2
    case dm2
    case cm2
    case mm2
    case acre
    case sqmi
    case sqyd
    case sqft
    case sqin
    case sqrd
    case qing
    case mu
    case fen
    case sqchi
    case sqcun
    
}



class MjModel: NSObject {
    
    let mjTypes = ["平方千米","公顷","公亩","平方米","平方分米","平方厘米","平方毫米","英亩","平方英里","平方码","平方英尺","平方英寸","平方竿","顷","亩","分","平方尺","平方寸"]
    let mjSigns = ["km²","ha","are","㎡","dm²","cm²","mm²","acre","sq.mi","sq.yd","sq.ft","sq.in","sq.rd","","","","","","",""]

    func kmTall(n: Double, type: MJType, reverse: Bool = false) -> Double {
        var km2 = n
        switch type {
        case .km2:
            break
        case .ha:
            if reverse {
                km2 = n / 100
            }else{
                km2 = n * 100
            }
        case .are:
            km2 = reverse ? n / 10000: n * 10000
            break
        case .m2:
            km2 = reverse ? n / 1000000: n * 1000000
            break
        case .dm2:
            km2 = reverse ? n / 100000000: n * 100000000
            break
        case .cm2:
            km2 = reverse ? n / 10000000000: n * 10000000000
            break
        case .mm2:
            km2 = reverse ? n / 1000000000000: n * 1000000000000
            break
        case .acre:
            km2 = reverse ? n / 247.1053815: n * 247.1053815
            break
        case .sqmi:
            km2 = reverse ? n / 0.3861022: n * 0.3861022
            break
        case .sqyd:
            km2 = reverse ? n / 1195990.046301: n * 1195990.046301
            break
        case .sqft:
            km2 = reverse ? n / 10763910.41671: n * 10763910.41671
            break
        case .sqin:
            km2 = reverse ? n / 1550003100.006: n * 1550003100.006
            break
        case .sqrd:
            km2 = reverse ? n / 39536.8610347: n * 39536.8610347
            break
        case .qing:
            km2 = reverse ? n / 15: n * 15
            break
        case .mu:
            km2 = reverse ? n / 1500: n * 1500
            break
        case .fen:
            km2 = reverse ? n / 15000: n * 15000
            break
        case .sqchi:
            km2 = reverse ? n / 9000000: n * 9000000
            break
        case .sqcun:
            km2 = reverse ? n / 900000000: n * 900000000
            break
        }
        return km2
    }
    
    func allChange(d: Double, type: MJType) -> [String] {
        
        let km = kmTall(n: d, type: type, reverse: true)
        
        
        
        return ["\(kmTall(n: km, type: .km2))\(mjSigns[0])","\(kmTall(n: km, type: .ha))\(mjSigns[1])",
                "\(kmTall(n: km, type: .are))\(mjSigns[2])","\(kmTall(n: km, type: .m2))\(mjSigns[3])",
                "\(kmTall(n: km, type: .dm2))\(mjSigns[4])","\(kmTall(n: km, type: .cm2))\(mjSigns[5])",
                "\(kmTall(n: km, type: .mm2))\(mjSigns[6])","\(kmTall(n: km, type: .acre))\(mjSigns[7])",
                "\(kmTall(n: km, type: .sqmi))\(mjSigns[8])","\(kmTall(n: km, type: .sqyd))\(mjSigns[9])",
                "\(kmTall(n: km, type: .sqft))\(mjSigns[10])","\(kmTall(n: km, type: .sqin))\(mjSigns[11])",
                "\(kmTall(n: km, type: .sqrd))\(mjSigns[12])","\(kmTall(n: km, type: .qing))\(mjSigns[13])",
                "\(kmTall(n: km, type: .mu))\(mjSigns[14])","\(kmTall(n: km, type: .fen))\(mjSigns[15])",
                "\(kmTall(n: km, type: .sqchi))\(mjSigns[16])","\(kmTall(n: km, type: .sqcun))\(mjSigns[17])"]
        
        
    }
    
    
    
    

}
